<template>
  <el-container style="height:auto;border: 1px solid #eee">
    <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
      <el-menu router :default-openeds="['1','2','3']">
        <el-submenu v-for="(item,index) in $router.options.routes" :index="index+''" v-if="item.admin">
          <template slot="title"><i class="el-icon-setting"></i>{{item.name}}</template>
          <el-menu-item v-for="(item2,index2) in item.children" :index="item2.path" :class="$route.path==item2.path?'is-active':''">{{item2.name}}</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <el-dropdown>
          <i class="el-icon-setting" style="margin-right: 15px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="open">反馈</el-dropdown-item>
            <el-dropdown-item @click.native="exit">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <span>{{this.username}}</span>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data(){
    return{
      username:''
    }
  },
  methods: {
    open() {
      this.$prompt('请输入反馈', '反馈', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        this.$message({
          type: 'success',
          message: '反馈已提交'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        });
      });
    },
    exit(){
      this.$store.dispatch('logout');
      this.$router.push('/login');//跳转页面
      console.log(this.$store.state);
    },
    getUsername(){
      const _this=this;
      axios.get('http://localhost:8181/user/getUsername/'+this.$store.state.account).then(function (resp){
        _this.username=resp.data;
      })
    }
  },created(){
    this.getUsername();
}
}
</script>

<style scoped>

</style>